#include "tile.h"
#include <QDebug>

Tile::Tile(QWidget *parent) : QPushButton(parent)
{
    //设置按钮大小为图片大小
    this->setFixedSize(40, 40);
}

void Tile::setStatus(int status, bool isEditable)
{
    this->status = status;
    this->isEditable = isEditable;

    statusToPath[0] = QString(":/res/wall.jpg");
    statusToPath[1] = QString(":/res/ground.jpg");
    statusToPath[2] = QString(":/res/starting_place.png");
    statusToPath[3] = QString(":/res/destination.png");

    this->setStyleSheet(QString("QPushButton{border-image: url(%1);}").arg(statusToPath[status]));
}

void Tile::mousePressEvent(QMouseEvent * e)
{
    if (isEditable) {
        return;
    }
    return QPushButton::mousePressEvent(e);
}

void Tile::setSize(int Size)
{
    setFixedSize(Size, Size);
    setIconSize(QSize(Size, Size));
}

void Tile::changeStatus()
{
    if(status != 3) {
        status++;
    } else {
        status = 0;
    }
    //设置图标
    this->setStyleSheet(QString("QPushButton{border-image: url(%1);}").arg(statusToPath[status]));
//    QPixmap pix;
//    pix.load(statusToPath[status]);
//    setIcon(QIcon(pix));
}

void Tile::changeStatus(int status)
{
    this->status = status;
    //设置图标
//    QPixmap pix;
//    pix.load(statusToPath[status]);
//    setIcon(QIcon(pix));
    this->setStyleSheet(QString("QPushButton{border-image: url(%1);}").arg(statusToPath[status]));
}

